#include <bitset>
#include <algorithm>
#include <numeric>

class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        auto xor = std::accumulate(nums.cbegin(), nums.cend(), 0, std::xor<int>());
        auto mask = xor & -xor;
        std::vector<int> ret{0, 0};
        for (auto num : nums){
            if (num&mask==0) ret[0] ^= num;
            else ret[1]^=num;
        }
        return ret;
    }
};